#ifndef LS72B_H
#define LS72B_H

#include <iostream>
#include <vector>
#include <thread>
#include <queue>
#include <mutex>
#include <cmath>
#include <chrono>
#include <cstring>
#include <functional>
#include <string>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <errno.h>

typedef uint64_t u_int64;

typedef struct _MuchLidarData
{
	int ID = 0;
	float Distance = 0.0;
	int Intensity = 0.0;
} MuchLidarData;

typedef std::function<void(std::vector<MuchLidarData>, int)> Fun;

class GetLidarData_LS72B 
{
public:
	explicit GetLidarData_LS72B();   
	~GetLidarData_LS72B();

    bool isFrameOK = false;                                         

	void onSerialPort(std::string com_name, int baud_rate);
	void LidarStar();                                                  
	void LidarStop();                                                   
	std::vector<MuchLidarData> getLidarPerFrameDate();                  
	void readLidarState();                                             
	std::string getLidarState();                                        
	void setLidarHz(u_int Hz);                                          

private:
	int fd;                   // File descriptor for the serial port
	std::vector<char> DataTmpBuff;             
	std::string strState;         
	std::vector<MuchLidarData> all_lidardata, all_lidardata_d;
	bool isQuit = false;
	int Model = 0;
	Fun* callback = NULL;
	std::vector<MuchLidarData> LidarPerFrameDate{0};

	bool open(const char* portname, int baudrate, char parity, char databit, char stopbit);
	int send(char* dat, int datalong);
	std::string receive();
	void close();

	void sendLidarData();                                         
	void deleteLidarData();                                          
};

#endif